package com.ltxtiyu.video.api;

import com.ltxtiyu.video.tool.ApiTool;
import com.ltxtiyu.video.utils.SignatureUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class ApiShare {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(HttpServletRequest request, Model model){
        // 获取accessToken
        String WX_APPID = "wxdeacc58191025225";
        String WX_SECRET = "b2b45575df5c78b5b5eda7540799b14b";
        String accessToken = ApiTool.getAccessToken(WX_APPID,WX_SECRET);
        System.out.println(">>>>>"+accessToken);
        Map<String, Object> map = SignatureUtil.requestUrlSignature(request, accessToken);
        model.addAttribute("appid", WX_APPID);
        model.addAttribute("signature", map.get("signature"));
        model.addAttribute("nonceStr", map.get("nonceStr"));
        model.addAttribute("timestamp", map.get("timestamp"));
//        return "{\"ret\":\"40\",\"msg\":\"网络异常\"}";
        return "onBack("+"{\"ret\":\"40\",\"msg\":\"网络异常\"}"+")";
//        return "/hello";
    }
}
